package com.frogs.ucenter.v1.request;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class UserRechargeConsumeBackRequest extends Request {

	/**
	 * 
	 */
	private static final long serialVersionUID = 23992534210034764L;
	
	private String orderId;
	
	private BigDecimal consumeMoney;
	
	private Integer userId;

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public BigDecimal getConsumeMoney() {
		return consumeMoney;
	}

	public void setConsumeMoney(BigDecimal consumeMoney) {
		this.consumeMoney = consumeMoney;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}


	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.orderId = requestInfo.getParameter(ApiUrlParamEnum.orderId.getParamName(), "");
		this.consumeMoney = requestInfo.getBigDecimalParameter(ApiUrlParamEnum.consumeMoney.getParamName());
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), -1);
		if (consumeMoney == null || BigDecimal.valueOf(0).compareTo(consumeMoney) == 0 || BigDecimal.valueOf(0).compareTo(consumeMoney) == 1) {
			throw new RequestIllegalException("error consumeMoney: " + consumeMoney);
		}
		if(StringUtil.isEmpty(orderId)){
			throw new RequestIllegalException("error orderId:"+orderId);
		}
		if( userId < 0) {
			throw new RequestIllegalException("error userId:"+userId);
		}
	}

}
